package org.ziegler.log.analysis.resultHandler;

import java.util.ArrayList;
import java.util.List;

import org.ziegler.log.analysis.LogCore;
import org.ziegler.log.analysis.core.SplitColumn;

public class LimitResultHandler implements ResultHandler {

    private final int limitCount;
    /** 记录所有日志 */
    private final List<SplitColumn> allSplitError = new ArrayList<>();

    /** 总数量 */
    private int totalCount = 0;

    public LimitResultHandler(int limitCount) {
        this.limitCount = limitCount;
    }

    @Override
    public void addResult(SplitColumn splitColumn) {
        ++ totalCount;

        if (allSplitError.size() > limitCount) {
            return ;
        }

        allSplitError.add(splitColumn);
    }

    @Override
    public void output() {
        LogCore.log("总过滤剩余记录数量：" + totalCount + "，下面显示限制最大数量：" + limitCount);
        for (SplitColumn splitColumn : allSplitError) {
            LogCore.log(splitColumn.getStr());
        }
    }

}
